package com.css.fxfzypg.modules.baseData.service.impl;

import com.css.fxfzypg.modules.baseData.dto.PetIndProjectDto;
import com.css.fxfzypg.modules.baseData.entity.KeyProjectEntity;
import com.css.fxfzypg.modules.baseData.repository.PetIndProjectRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author
 * @date 2022/10/6 14:52
 * @description
 **/
@Repository
public class PetIndProjectRepositoryImpl implements PetIndProjectRepository {
    @Resource
    private JdbcTemplate jdbcTemplate;

    @Autowired
    private NamedParameterJdbcTemplate namedParameterJdbcTemplate;

    @Override
    public void update(KeyProjectEntity keyProjectEntity) {
        String sql="update data_key_project set dkp_province =:dkpProvince ,dkp_city =:dkpCity ,dkp_prefecture =:dkpPrefecture " +
                ",dkp_name =:dkpName ,dkp_location =:dkpLocation ,dkp_type =:dkpType ,dkp_scale =:dkpScale ,dkp_year =:dkpYear " +
                ",dkp_condition=:dkpCondition ,dkp_actuality =:dkpActuality ,dkp_update_user =:dkpUpdateUser, dkp_update_time =:dkpUpdateTime " +
                ",dkp_province_id =:dkpProvinceId ,dkp_city_id =:dkpCityId ,dkp_prefecture_id =:dkpPrefectureId " +
                "where dkp_id='"+keyProjectEntity.getDkpId()+"'";
        SqlParameterSource source = new BeanPropertySqlParameterSource(keyProjectEntity);
        namedParameterJdbcTemplate.update(sql, source);
    }

    @Override
    public List<PetIndProjectDto> findInIdList(List<String> idList) {
        String sql="select * from data_key_project where  dkp_id in ('"+String.join("','", idList)+"')";
        List<PetIndProjectDto> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(PetIndProjectDto.class));
        return list;
    }
}
